package com.qf.admin.controller.system;

import com.qf.admin.domain.vo.TokenVO;
import com.qf.common.aspect.ApiOperationLog;
import com.qf.common.core.domain.ResponseResult;
import com.qf.jwt.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: sin
 * @Date: 2024/10/13 15:49
 * @Description:
 **/
@RestController
@Slf4j
@RequestMapping("/auth")
@Api(tags = "01.鉴权接口")
public class AuthController {

    @Resource
    private JwtUtil jwtUtil;

    /**
     * @author: sin
     * @Description 刷新token 根据旧的token生成新的token,过期时间延迟
     */
    @ApiOperation(value = "刷新token")
    @ApiOperationLog(description = "刷新token")
    @PostMapping("/refreshToken")
    public ResponseResult<Map<String, Object>> refreshToken(@RequestBody  @Validated TokenVO tokenVO){
        String refreshToken = jwtUtil.refreshToken(tokenVO.getRefreshToken());
        String accessToken = refreshToken;
        Map<String, Object> data = new HashMap<>();
        data.put("accessToken",accessToken);
        data.put("refreshToken",refreshToken);
        data.put("expires", jwtUtil.getExpriTime());

        return ResponseResult.success(data);
    }
}
